package it.asvp.asvp_portal.data.dao.impl;

import it.asvp.asvp_portal.asvp_util.enumerative.RoleName;
import it.asvp.asvp_portal.data.dao.RoleDao;
import it.asvp.asvp_portal.data.entity.member.Role;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

@Repository
public class RoleDaoImpl extends GenericDaoImpl<Long, Role> implements RoleDao {

  private static final Log log = LogFactory.getLog(RoleDaoImpl.class);

  @Override
  public Role findByRoleName(RoleName roleName) {
    log.debug("getting Role instance with role name: " + roleName);

    Criteria cr = getSession().createCriteria(Role.class);
    cr.add(Restrictions.eq("roleName", roleName));
    Role r = (Role) cr.uniqueResult();
    log.debug("findById eseguito con successo");
    return r;
  }

}
